"""
execute command
"""

import subprocess


def execute(command: str) -> dict:
    process = subprocess.Popen(
        command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
    )
    output, error = process.communicate()
    if process.returncode == 0:
        log = {
            "type": "info",
            "context": f"{command} \n {output.decode()} \n {error.decode()} \n",
        }
    else:
        print(f"ERROR({process.returncode}): {command} \n {error.decode()} \n")
        log = {
            "type": "error",
            "context": f"ERROR({process.returncode}): {command} \n {error.decode()} \n",
        }

    return log
